package com.changgou.search.listener;

import com.changgou.entity.Constants;
import com.changgou.search.service.SearchManageService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: zhengke
 * @date: 2020/12/18
 * @return:
 * @description: 商品上架的MQ监听器
 */
@Component
public class GoodsUpDownListener {
    @Autowired
    private SearchManageService searchManageService;

    /**
     * 上架监听方法
     * @param spuId
     */
    @RabbitListener(queues = Constants.SEARCH_ADD_QUEUE)
    public void goodsUp(String spuId){
        //调用service层，完成sku数据查询及导入到ES中
        searchManageService.importBySpuId(spuId);
    }

    /**
     * 下架监听方法
     * @param spuId
     */
    @RabbitListener(queues = Constants.SEARCH_DEL_QUEUE)
    public void goodsDel(String spuId){
        //调用service层，完成从ES中删除sku数据
        searchManageService.delBySpuId(spuId);
    }
}
